<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
defined ('IN_AGORA') or die;

class TaskController extends AgoraPollsController {

	function _default() {
		$forum_model = & Model::getInstance('ForumModel');
		$forum = $forum_model->load($this->id);
		if ($forum['single_topic']) {  // Check for Single Topic forums
			if ($forum_model->hasTopic($forum['id'], $this->agora_user['username'] )) {//User has started a topic, cant start another so we Close to him.
				$this->view->template = 'post/max_met';
				return;
			}
		}

		$this->authenticate($this->id,'post_poll');

		$catnav_helper = & $this->helper('catnav');
		$catnav_helper->fromForum($this->id);
		
		$this->view->assign('form_url', JURI::base(true) . '/');
		
		$this->view->template = "poll/select";
	}

	function select_forum() {		    
		$url = Agora::getSelf();
		$mainframe =& JFactory::getApplication('site');
		if ($mainframe->getCfg('sef')) {
			$url=substr($url, 0, strrpos($url, '/'));
			$this->view->assign('self_url',$url);
		}
		$this->view->assign('form_url', JURI::base(true) . '/');
		// filter allowed forums
		$forums = $this->forumList;

		if (!$this->agora_user['is_superadmin']) {
			foreach ($forums as $cat_id => $cat) {
				$this->access_model->filterForums($forums[$cat_id]['forums'],$this->agora_user['id'],'post_poll');
				/*
				foreach ($forums[$cat_id]['forums'] as $forum_id=>$forum) {
					$parent_id = $forum['parent_forum_id'];
					if ($parent_id == 0) continue;
					if (!isset($forums[$cat_id]['forums'][$parent_id])) {
						unset($forums[$cat_id]['forums'][$forum_id]);
					}
				}*/

				if (empty($forums[$cat_id]['forums'])) {
					unset($forums[$cat_id]);
				}
			}
		}

		$this->view->assign('allowed_forums',$forums);
		$this->view->template = "poll/select_forum";
	}
}

?>
